#include "sys.h"


int  read_fd;
int write_fd;

void init(){
	read_fd = open("../text", O_RDONLY);
		assert(fd!=-1);
	write_fd = open("../recv_text", O_RDWR);
		assert(fd!=-1);
}
int sendto(int sockfd){
	int len;
	int buflen = 1024*10;
	
	debug_info("send data!\n");
	len = (rand() % (buflen)) + 1;  //assert len !=0 
	
	buf = malloc(len);
	len = read(read_fd, buf, len);
	assert(len!=-1);
	write(sockfd, buf,len);
	
}

void recv(int sockfd){
	msg_t* msg;
	int len;
	msg = recv_data(1);

	read(sockfd, buf, len);
	printf("recv msg id[%llu] msg->hr.len[%d]\n", msg->id, msg->hr.len);
	len = write(write_fd, msg->buf, msg->hr.len);
	assert(len ==  msg->hr.len);
	free_msg(msg);
}

int newConnect(){
	  int client_sockfd;
	   int rval;
	   struct sockaddr_in remote_addr;

	   memset(&remote_addr,0,sizeof(remote_addr));

	   remote_addr.sin_family = AF_INET;
	   remote_addr.sin_addr.s_addr = inet_addr("115.29.42.68");
	   remote_addr.sin_port = htons(10000);

	   if((client_sockfd = socket(PF_INET,SOCK_STREAM,0))<0){
		   perror("socket");
		   return 1;
	   }

	   if(connect(client_sockfd,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr))<0){
			 printf("errno:%d\n", errno);
			 perror("connect");
			 return 1;
	  }
	   return client_sockfd;
}


void test(){
	
}
int main(){
		
}

